package com.yc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.entity.Admin;
import com.yc.mapper.AdminMapper;
import com.yc.service.IAdminService;
import com.yc.util.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * InnoDB free: 4096 kB 服务实现类
 * </p>
 *
 * @author ly
 * @since 2022-06-06
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {
    @Resource
    private AdminMapper adminMapper;

    @Override
    public List< Admin > login(String name, String password) {
        Map<String,Object> map=new HashMap<>();
        map.put("adcount",name);
        map.put("password",password);
        return adminMapper.selectByMap(map);
    }

    @Override
    public List< Admin > queryByAdname(String name) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("adcount",name);
        return adminMapper.selectList(queryWrapper);
    }

    @Override
    public Integer updateLastTime(Admin admin) {
        UpdateWrapper updateWrapper=new UpdateWrapper();
        updateWrapper.set("lastlogineddate", DateUtil.Format(new Date()));
        return adminMapper.update(admin,updateWrapper);
    }

    @Override
    public Integer updateAdminInfo(Admin admin) {
        return adminMapper.updateById(admin);
    }

    @Override
    public Integer updateAdminPwd(Admin admin,String newpwd) {
        UpdateWrapper updateWrapper=new UpdateWrapper();
        updateWrapper.set("password",newpwd);
        return adminMapper.update(admin,updateWrapper);
    }
}
